/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import model.FamiliaMateriaPrima;
import model.Usuario;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author Fran
 */
public class FamiliaMateriaPrimaDAO {
    
    public FamiliaMateriaPrimaDAO(){
            
        session = HibernateUtil.getSessionFactory().openSession();
    
    }
    private Session session;
    
    public void inserir(FamiliaMateriaPrima familiamateria)
    {
        
        Transaction t = session.beginTransaction();
        session.save(familiamateria);
        t.commit();
            
    } 
    
    public List<FamiliaMateriaPrima> findMatPrimadaFamilia(int codfamilia){
        
        Query que = session.createQuery("From FamiliaMateriaPrima where famcodigo = "+codfamilia);
        
        return que.list();
        
    }
    
    public void update(FamiliaMateriaPrima fmp){
        Transaction t = session.beginTransaction();
        session.merge(fmp);
        t.commit();
    }
    
    
}
